package com.biz.primus.management.coupon.type.init;

import com.biz.primus.account.service.AuthInitializeService;
import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.sso.auth.vo.GrantedAuthority;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenuItemVO;
import com.biz.primus.model.sso.auth.vo.ResourceVO;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.google.common.collect.Lists.newArrayList;

/**
 * @author david-liu
 */
@Service
public class InitManager {

    private final AuthInitializeService authInitializeService;

    @Autowired
    public InitManager(AuthInitializeService authInitializeService) {
        this.authInitializeService = authInitializeService;
    }

    @PostConstruct
    public void setup() {

        List<MenuGroupVO> menuGroups = newArrayList();
        MenuGroupVO menuGroupVO = new MenuGroupVO("MANAGEMENT_OPERATION", "运营管理", "运营管理页面", "fa fa-gear", CommonStatus.ENABLE, 999);
        List<MenuItemVO> menuItems = newArrayList();
        MenuItemVO menuManageMenuItemVO = new MenuItemVO("MANAGEMENT_OPERATION_COUPON", "优惠券管理", "优惠券管理", "fa fa-list", "management/couponType.do", CommonStatus.ENABLE, 1);
        menuManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_CAT;OPT_CAT_LIST"));
        List<ResourceVO> resources = newArrayList();
        resources.add(new ResourceVO("MANAGEMENT_DEMO_CAT_EDIT", "修改", "修改猫", CommonStatus.ENABLE, new GrantedAuthority("OPT_CAT_EDIT"), 1));
        resources.add(new ResourceVO("MANAGEMENT_DEMO_CAT_DELETE", "删除", "删除猫", CommonStatus.ENABLE, new GrantedAuthority("OPT_CAT_DELETE"), 2));
        menuManageMenuItemVO.setResources(resources);
        menuItems.add(menuManageMenuItemVO);
        menuGroupVO.setMenuItems(menuItems);
        menuGroups.add(menuGroupVO);
        authInitializeService.registerMenu(menuGroups);
    }
}
